package com.atg.atgchat.init.websocket.serivce.adapter;

import com.atg.atgchat.init.user.model.entity.User;
import com.atg.atgchat.init.websocket.model.enums.WebSocketResponseEnum;
import com.atg.atgchat.init.websocket.vo.resp.WebSocketBaseResp;
import com.atg.atgchat.init.websocket.vo.resp.WebSocketLoginSuccessResp;
import com.atg.atgchat.init.websocket.vo.resp.WebSocketLoginUrlResp;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;

/*
author: atg
time: 2025/1/13 15:19
*/
public class WebSocketAdapter {

    public static WebSocketBaseResp<?> buildResp(WxMpQrCodeTicket wxMpQrCodeTicket) {
        WebSocketBaseResp<WebSocketLoginUrlResp> webSocketBaseResp = new WebSocketBaseResp();
        webSocketBaseResp.setType(WebSocketResponseEnum.LOGIN_URL.getType());
        webSocketBaseResp.setData(new WebSocketLoginUrlResp(wxMpQrCodeTicket.getUrl()));
        return webSocketBaseResp;
    }

    public static WebSocketBaseResp<?> buildLoginResp(User user, String token) {
        WebSocketBaseResp<WebSocketLoginSuccessResp> webSocketBaseResp = new WebSocketBaseResp();
        webSocketBaseResp.setType(WebSocketResponseEnum.LOGIN_SUCCESS.getType());
        WebSocketLoginSuccessResp successResp = WebSocketLoginSuccessResp.builder()
                .uid(user.getId())
                .avatar(user.getAvatar())
                .token(token)
                .name(user.getName())
                .build();
        webSocketBaseResp.setData(successResp);
        return webSocketBaseResp;
    }

    public static WebSocketBaseResp<?> buildWaitAuthorizationMessage() {
        WebSocketBaseResp<WebSocketLoginUrlResp> webSocketBaseResp = new WebSocketBaseResp();
        webSocketBaseResp.setType(WebSocketResponseEnum.LOGIN_SCAN_SUCCESS.getType());
        return webSocketBaseResp;
    }

    public static WebSocketBaseResp<?> buildInvalidTokenResp() {
        WebSocketBaseResp<WebSocketLoginUrlResp> webSocketBaseResp = new WebSocketBaseResp();
        webSocketBaseResp.setType(WebSocketResponseEnum.INVALIDATE_TOKEN.getType());
        return webSocketBaseResp;

    }
}
